<template>
  <div class="toolbar">
    <div class="actions">
      <div
        class="item"
        :class="{
          active: modelValue === 'addLabel',
        }"
        @click="handleChangeActive('addLabel')"
      >
        添加标注
      </div>
      <div
        class="item"
        :class="{
          active: modelValue === 'move',
        }"
        @click="handleChangeActive('move')"
      >
        <el-tooltip
          effect="dark"
          content="快捷键（按住空格键）"
          placement="bottom"
        >
          移动
        </el-tooltip>
      </div>
    </div>
    <div class="setting">
      <div class="item" @click="handleSettingClick">保存</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps<{
  modelValue: 'addLabel' | 'move'
}>()

interface EmitsType {
  (e: 'update:modelValue', val: 'addLabel' | 'move'): void
}
const emit = defineEmits<EmitsType>()

const actionType = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emit('update:modelValue', val)
  },
})

const handleChangeActive = (val: 'addLabel' | 'move') => {
  actionType.value = val
}

const handleSettingClick = () => {
  // 这里可以添加设置的逻辑
  console.log('设置按钮被点击')
}
</script>

<style scoped lang="scss">
.toolbar {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  .actions {
    display: flex;
    align-items: center;
  }
  .setting {
    display: flex;
    align-items: center;
  }
  .item {
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
    margin-right: 10px;
    cursor: pointer;
    color: #fff;
    border-radius: 5px;
    font-size: 16px;
    &:hover {
      opacity: 0.8;
      background-color: #646464;
    }
    &.active {
      background-color: #646464;
    }
  }
}
</style>
